package cn.studyjava.verify.util;

import java.io.IOException;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * <p>
 * Description:
 * </p>
 * 
 * @author: zsljava
 * @version 1.0.0
 * <p>
 * History:
 * -----------------------------------------------
 * @Date: 2017年10月18日 下午2:30:19
 * @author: zsljava
 * @version 1.0.0
 * @OP: Create
 * -----------------------------------------------
 * </p>
 *
 * @since
 * @see
 */
public class JsonUtil {

	private final static ObjectMapper OBJECT_MAPPER = new ObjectMapper();  
	
	public static <T> T json2pojo(String jsonStr, Class<T> clazz) {  
		try {
			return OBJECT_MAPPER.readValue(jsonStr, clazz);
		} catch (IOException e) {
			e.printStackTrace();
		}  
		return null;
	}
	
	public static String obj2json(Object obj) {  
        try {
			return OBJECT_MAPPER.writeValueAsString(obj);
		} catch (JsonProcessingException e) {
			e.printStackTrace();
		}  
        return null;
    } 
}
